package com.manage.web.controller.function;

import com.manage.common.core.controller.BaseController;
import com.manage.common.core.domain.AjaxResult;
import com.manage.common.core.page.TableDataInfo;
import com.manage.common.enums.BusinessType;
import com.manage.common.utils.poi.ExcelUtil;
import com.manage.function.domain.FileManagement;
import com.manage.function.service.IFileManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.manage.common.annotation.Log;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author jinghj
 * @date 2025-03-04
 * 提供接口给前端访问
 */
@Api(value ="/function/management",  tags = "文件管理，用于存储文件的基本信息和操作记录管理接口")
@RestController
@RequestMapping("/function/management")
public class FileManagementController extends BaseController {

    @Autowired
    private IFileManagementService fileManagementService;

    /**
     * 根据实体获取数据
     */
    @ApiOperation(value = "根据实体获取数据" , notes = "根据实体获取数据" , httpMethod = "POST")
    @PreAuthorize("@ss.hasPermi('function:management:list')")
    @PostMapping("/selectByEntity")
    public TableDataInfo selectByEntity(@ApiParam(value = "FileManagement查询条件", required = false) @RequestBody FileManagement fileManagement)
    {
        startPage();
        List<FileManagement> list = fileManagementService.selectFileManagementList(fileManagement);
        return getDataTable(list);
    }

    /**
     * 导出数据Excle文件
     */
    @ApiOperation(value = "导出列表", notes = "将列表数据导出为 Excel 文件",httpMethod = "POST")
    @PreAuthorize("@ss.hasPermi('function:management:export')")
    @Log(title = "文件管理，用于存储文件的基本信息和操作记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @ApiParam(value = "FileManagement查询条件", required = false)  FileManagement fileManagement)
    {
        List<FileManagement> list = fileManagementService.selectFileManagementList(fileManagement);
        ExcelUtil<FileManagement> util = new ExcelUtil<FileManagement>(FileManagement.class);
        util.exportExcel(response, list, "文件管理，用于存储文件的基本信息和操作记录数据");
    }

    /**
     * 获取单条详细信息
     */
    @ApiOperation(value = "获取单条详细信息", notes = "获取单条详细信息", httpMethod = "GET")
    @PreAuthorize("@ss.hasPermi('function:management:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam(value = "id主键", required = true) @PathVariable("id") Long id)
    {
        return success(fileManagementService.selectFileManagementById(id));
    }

    /**
     * 新增数据接口
     */
    @ApiOperation(value = "新增数据" , notes = "新增数据" , httpMethod = "POST")
    @PreAuthorize("@ss.hasPermi('function:management:add')")
    @Log(title = "文件管理，用于存储文件的基本信息和操作记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@ApiParam(value = "FileManagement新增数据", required = true) @RequestBody FileManagement fileManagement)
    {
        return toAjax(fileManagementService.insertFileManagement(fileManagement));
    }

    /**
     * 更新数据接口
     */
    @ApiOperation(value = "更新数据" , notes = "更新数据" , httpMethod = "PUT")
    @PreAuthorize("@ss.hasPermi('function:management:edit')")
    @Log(title = "文件管理，用于存储文件的基本信息和操作记录", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult update(@ApiParam(value = "FileManagement修改数据", required = true) @RequestBody FileManagement fileManagement)
    {
        return toAjax(fileManagementService.updateFileManagement(fileManagement));
    }

    /**
     * 批量删除数据接口
     */
    @ApiOperation(value = "根据ids删除数据" , notes = "根据ids删除数据" , httpMethod = "DELETE")
    @PreAuthorize("@ss.hasPermi('function:management:deleteList')")
    @Log(title = "文件管理，用于存储文件的基本信息和操作记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult deleteList(@ApiParam(value = "ids主键数组", required = true) @PathVariable Long[] ids)
    {
        return toAjax(fileManagementService.deleteFileManagementByIds(ids));
    }
}
